home *** CD-ROM | disk | FTP | other *** search
/ Czech Logic, Card & Gambling Games / Logické hry.iso / hry / Fish Fillets / script / share / level_creation.lua < prev    next >
Encoding:
Text File  |  2005-07-16  |  7.5 KB  |  234 lines

  1.  
  2. -- -----------------------------------------------------------------
  3. LOOK_LEFT = 0
  4. LOOK_RIGHT = 1
  5.  
  6. VOLUME_LOW = 50
  7. VOLUME_LOWER = 75
  8. VOLUME_FULL = 100
  9.  
  10. TALK_INDEX_BOTH = -1
  11.  
  12. -- -----------------------------------------------------------------
  13. -- Room creation
  14. -- -----------------------------------------------------------------
  15. function createRoom(width, height, picture)
  16.     level_createRoom(width, height, picture)
  17.     sound_addSound("impact_light", "sound/share/sp-impact_light_00.ogg")
  18.     sound_addSound("impact_light", "sound/share/sp-impact_light_01.ogg")
  19.     sound_addSound("impact_heavy", "sound/share/sp-impact_heavy_00.ogg")
  20.     sound_addSound("impact_heavy", "sound/share/sp-impact_heavy_01.ogg")
  21.  
  22.     sound_addSound("dead_small", "sound/share/sp-dead_small.ogg")
  23.     sound_addSound("dead_big", "sound/share/sp-dead_big.ogg")
  24. end
  25.  
  26. function setRoomWaves(double_amp, periode, inv_speed)
  27.     game_setRoomWaves(double_amp/2, periode, 1/inv_speed)
  28. end
  29.  
  30. local models_table = {}
  31. function addModel(name, x, y, shape)
  32.     local model_index = game_addModel(name, x, y, shape)
  33.     local model = createObject(model_index)
  34.     models_table[model_index] = model
  35.     return model
  36. end
  37. function getModelsTable()
  38.     return models_table
  39. end
  40.  
  41. local unit_table = {}
  42. function getUnitTable()
  43.     return unit_table
  44. end
  45.  
  46. -- -----------------------------------------------------------------
  47. -- Model creation
  48. -- -----------------------------------------------------------------
  49. function createObject(model_index)
  50.     local object = {}
  51.     object.index = model_index
  52.     object.talk_phase = false
  53.  
  54.     object.addAnim = function(self, anim_name, filename, lookDir)
  55.         model_addAnim(self.index, anim_name, filename, lookDir)
  56.     end
  57.     object.runAnim = function(self, anim_name, phase)
  58.         model_runAnim(self.index, anim_name, phase)
  59.     end
  60.     object.setAnim = function(self, anim_name, phase)
  61.         model_setAnim(self.index, anim_name, phase)
  62.     end
  63.     object.useSpecialAnim = function(self, anim_name, phase)
  64.         local action = self:getAction()
  65.         if action ~= "busy" and action ~= "turn" and action ~= "activate" and self:isAlive() then
  66.             model_useSpecialAnim(self.index, anim_name, phase)
  67.         end
  68.     end
  69.     object.setEffect = function(self, effect_name)
  70.         model_setEffect(self.index, effect_name)
  71.     end
  72.  
  73.     object.getLoc = function(self)
  74.         return model_getLoc(self.index)
  75.     end
  76.     object.getAction = function(self)
  77.         return model_getAction(self.index)
  78.     end
  79.     object.getState = function(self)
  80.         return model_getState(self.index)
  81.     end
  82.     object.getTouchDir = function(self)
  83.         return model_getTouchDir(self.index)
  84.     end
  85.     object.isAlive = function(self)
  86.         return model_isAlive(self.index)
  87.     end
  88.     object.isOut = function(self)
  89.         return model_isOut(self.index)
  90.     end
  91.     object.isLeft = function(self)
  92.         return model_isLeft(self.index)
  93.     end
  94.     object.isAtBorder = function(self)
  95.         return model_isAtBorder(self.index)
  96.     end
  97.     object.getW = function(self)
  98.         return model_getW(self.index)
  99.     end
  100.     object.getH = function(self)
  101.         return model_getH(self.index)
  102.     end
  103.     object.isTalking = function(self)
  104.         return model_isTalking(self.index)
  105.     end
  106.     object.talk = function(self, dialog, volume, loops)
  107.         model_talk(self.index, dialog, volume, loops)
  108.     end
  109.     object.killSound = function(self)
  110.         model_killSound(self.index)
  111.     end
  112.     object.planDialog = function(self, delay, dialog, action)
  113.         planDialog(self.index, delay, dialog, action)
  114.     end
  115.     object.setGoal = function(self, goalname)
  116.         model_setGoal(self.index, goalname)
  117.     end
  118.     object.change_turnSide = function(self)
  119.         model_change_turnSide(self.index)
  120.     end
  121.     object.setBusy = function(self, busy)
  122.         model_setBusy(self.index, busy)
  123.     end
  124.  
  125.     return object
  126. end
  127.  
  128. -- -----------------------------------------------------------------
  129. -- Loading resources
  130. -- -----------------------------------------------------------------
  131. local function imgList(picture_00)
  132.     -- return table of available sprites _00, _01, _02, ...
  133.     --TODO: support others than .png
  134.     local list = {picture_00}
  135.     local index = 1
  136.     local ext = ".png"
  137.     local base, ok = string.gsub(picture_00, "_00"..ext.."$", "_")
  138.     while ok == 1 do
  139.         local next_file = base..index..ext
  140.         if index < 10 then
  141.             next_file = base.."0"..index..ext
  142.         end
  143.  
  144.         if file_exists(next_file) then
  145.             table.insert(list, next_file)
  146.         else
  147.             ok = 0
  148.         end
  149.         index = index + 1
  150.     end
  151.     return list
  152. end
  153.  
  154. function addItemAnim(model, picture_00)
  155.     -- store all "picture_*.png" sprites to object anim
  156.     local anim_name = "default"
  157.     for index, filename in ipairs(imgList(picture_00)) do
  158.         model:addAnim(anim_name, filename)
  159.     end
  160.  
  161.     model:setAnim(anim_name, 0)
  162. end
  163.  
  164. function addHeadAnim(model, directory, anim, phase)
  165.     local left_path = directory.."/heads/left/head_"..phase..".png"
  166.     if file_exists(left_path) then
  167.         model:addAnim(anim, left_path)
  168.         model:addAnim(anim, directory.."/heads/right/head_"..phase..".png",
  169.                 LOOK_RIGHT)
  170.     else
  171.         print("SCRIPT_WARNING head anim is not available", anim, directory, phase)
  172.     end
  173. end
  174. local function addBodyAnim(model, directory, anim, phase)
  175.     local picture_00 = directory.."/left/body_"..phase..".png"
  176.     for index, filename in ipairs(imgList(picture_00)) do
  177.         model:addAnim(anim, filename)
  178.         model:addAnim(anim,
  179.                 string.gsub(filename, "/left/body_", "/right/body_"),
  180.                 LOOK_RIGHT)
  181.     end
  182. end
  183. local function addBodyAnimBackward(model, directory, anim, phase)
  184.     local picture_00 = directory.."/left/body_"..phase..".png"
  185.     local list = imgList(picture_00)
  186.     for index = table.getn(list), 1, -1 do
  187.         local filename = list[index]
  188.         model:addAnim(anim, filename)
  189.         model:addAnim(anim,
  190.                 string.gsub(filename, "/left/body_", "/right/body_"),
  191.                 LOOK_RIGHT)
  192.     end
  193. end
  194.  
  195. function addFishAnim(model, look_dir, directory)
  196.     -- NOTE: remark fish in unit_table
  197.     unit_table[model.index] = model
  198.     if model:isLeft() and look_dir == LOOK_RIGHT then
  199.         model:change_turnSide()
  200.     end
  201.     model:setGoal("goal_escape")
  202.  
  203.     addBodyAnim(model, directory, "skeleton", "skeleton_00")
  204.     addBodyAnim(model, directory, "rest", "rest_00")
  205.  
  206.     addBodyAnim(model, directory, "vertical_up", "vertical_00")
  207.     addBodyAnimBackward(model, directory, "vertical_down", "vertical_00")
  208.  
  209.     addBodyAnim(model, directory, "swam", "swam_00")
  210.     addBodyAnim(model, directory, "turn", "turn_00")
  211.     addBodyAnim(model, directory, "talk", "talk_00")
  212.  
  213.     -- heads
  214.     addHeadAnim(model, directory, "head_talking", "talking_00")
  215.     addHeadAnim(model, directory, "head_talking", "talking_01")
  216.     addHeadAnim(model, directory, "head_talking", "talking_02")
  217.  
  218.     addHeadAnim(model, directory, "head_pushing", "pushing")
  219.     addHeadAnim(model, directory, "head_blink", "blink")
  220.  
  221.     addHeadAnim(model, directory, "head_all", "talking_00")
  222.     addHeadAnim(model, directory, "head_all", "pushing")
  223.     addHeadAnim(model, directory, "head_all", "blink")
  224.     addHeadAnim(model, directory, "head_all", "shock")
  225.     addHeadAnim(model, directory, "head_all", "smile")
  226.     addHeadAnim(model, directory, "head_all", "talking_01")
  227.     addHeadAnim(model, directory, "head_all", "talking_02")
  228.     addHeadAnim(model, directory, "head_all", "scowl_00")
  229.     addHeadAnim(model, directory, "head_all", "scowl_01")
  230.  
  231.     model:runAnim("rest")
  232. end
  233.  
  234.